// import express, { json } from "express";
const express = require("express");
const cors = require("cors");
const app = express();

// 中间件设置
app.use(cors());
app.use(express.json()); // 用于解析 JSON 格式的请求体

app.get("/home/list", (req, res) => {
  // 定义接口
  res.send({
    code: 200,
    message: "获取列表成功",
    data: {
      salesTotal: 114779,
      salesToday: 112356,
      salesGrowthLastDay: -19.16,
      salesGrowthLastMonth: 56.67,

      visitTotal: 88460,
      visitToday: 1234,
      visitTrend: [
        610, 432, 220, 534, 790, 430, 220, 320, 532, 320, 834, 690, 530, 220,
        620,
      ],

      payTotal: 182425,
      payRate: 60.2,
      payTrend: [
        410, 82, 200, 334, 390, 330, 220, 150, 82, 200, 134, 290, 330, 150,
      ],

      activityRate: 78,
      activityGrowthLastDay: -17.7,
      activityGrowthLastMonth: 47.12,

      orderFullYearAxis: [
        "1月",
        "2月",
        "3月",
        "4月",
        "5月",
        "6月",
        "7月",
        "8月",
        "9月",
        "10月",
        "11月",
        "12月",
      ],
      orderFullYear: [410, 82, 200, 334, 390, 330, 220, 150, 82, 200, 134, 290],
      userFullYearAxis: [
        "1月",
        "2月",
        "3月",
        "4月",
        "5月",
        "6月",
        "7月",
        "8月",
        "9月",
        "10月",
        "11月",
        "12月",
      ],
      userFullYear: [110, 120, 90, 220, 175, 212, 192, 95, 88, 120, 250, 310],

      orderRank: [
        {
          no: 1,
          name: "肯德基",
          money: "323,234",
        },
        {
          no: 2,
          name: "麦当劳",
          money: "299,132",
        },
        {
          no: 3,
          name: "肯德基",
          money: "283,998",
        },
        {
          no: 4,
          name: "海底捞",
          money: "266,223",
        },
        {
          no: 5,
          name: "西贝筱面村",
          money: "223,445",
        },
        {
          no: 6,
          name: "汉堡王",
          money: "219,663",
        },
        {
          no: 7,
          name: "真功夫",
          money: "200,997",
        },
      ],

      userRank: [
        {
          no: 1,
          name: "麦当劳",
          money: "211,335",
        },
        {
          no: 2,
          name: "肯德基",
          money: "210,597",
        },
        {
          no: 3,
          name: "必胜客",
          money: "200,998",
        },
        {
          no: 4,
          name: "海底捞",
          money: "199,220",
        },
        {
          no: 5,
          name: "西贝筱面村",
          money: "195,444",
        },
        {
          no: 6,
          name: "汉堡王",
          money: "180,161",
        },
        {
          no: 7,
          name: "真功夫",
          money: "172,995",
        },
      ],
      
      seeRank: [
        {
          no: 1,
          name: "必胜客",
          money: "221,335",
        },
        {
          no: 2,
          name: "麦当劳",
          money: "210,597",
        },
        {
          no: 3,
          name: "肯德基",
          money: "200,998",
        },
        {
          no: 4,
          name: "海底捞",
          money: "199,220",
        },
        {
          no: 5,
          name: "华莱士",
          money: "195,444",
        },
        {
          no: 6,
          name: "真功夫",
          money: "180,161",
        },
        {
          no: 7,
          name: "汉堡王",
          money: "172,995",
        },
      ],

      searchWord: [
        {
          word: "北京",
          count: 3440,
          user: 1626,
        },
        {
          word: "上海",
          count: 8101,
          user: 6660,
        },
        {
          word: "广州",
          count: 7814,
          user: 2196,
        },
        {
          word: "深圳",
          count: 8888,
          user: 7102,
        },
        {
          word: "南京",
          count: 6204,
          user: 1949,
        },
        {
          word: "杭州",
          count: 8159,
          user: 3548,
        },
        {
          word: "合肥",
          count: 269,
          user: 151,
        },
        {
          word: "济南",
          count: 2045,
          user: 1320,
        },
        {
          word: "太原",
          count: 5693,
          user: 2297,
        },
        {
          word: "成都",
          count: 4850,
          user: 1635,
        },
        {
          word: "重庆",
          count: 906,
          user: 269,
        },
        {
          word: "苏州",
          count: 5576,
          user: 3937,
        },
        {
          word: "无锡",
          count: 1576,
          user: 796,
        },
        {
          word: "常州",
          count: 9002,
          user: 8508,
        },
        {
          word: "温州",
          count: 8103,
          user: 4903,
        },
        {
          word: "哈尔滨",
          count: 7961,
          user: 6173,
        },
        {
          word: "长春",
          count: 5916,
          user: 3117,
        },
        {
          word: "大连",
          count: 5012,
          user: 78,
        },
        {
          word: "沈阳",
          count: 8410,
          user: 5696,
        },
        {
          word: "拉萨",
          count: 3385,
          user: 2547,
        },
        {
          word: "呼和浩特",
          count: 4672,
          user: 34,
        },
        {
          word: "武汉",
          count: 7386,
          user: 4047,
        },
        {
          word: "南宁",
          count: 6192,
          user: 612,
        },
        {
          word: "必胜客",
          count: 3504,
          user: 2480,
        },
        {
          word: "肯德基",
          count: 3727,
          user: 2527,
        },
        {
          word: "麦当劳",
          count: 8959,
          user: 6198,
        },
        {
          word: "海底捞",
          count: 5295,
          user: 2264,
        },
        {
          word: "美食",
          count: 7348,
          user: 5555,
        },
        {
          word: "商超",
          count: 1628,
          user: 1295,
        },
        {
          word: "水果",
          count: 892,
          user: 215,
        },
        {
          word: "跑腿",
          count: 254,
          user: 40,
        },
        {
          word: "送药",
          count: 8377,
          user: 4363,
        },
        {
          word: "烩饭",
          count: 2009,
          user: 1080,
        },
        {
          word: "面条",
          count: 7684,
          user: 4299,
        },
        {
          word: "小龙虾",
          count: 3187,
          user: 562,
        },
        {
          word: "牛肉",
          count: 3612,
          user: 3449,
        },
        {
          word: "鸡腿",
          count: 4460,
          user: 367,
        },
        {
          word: "全家桶",
          count: 7206,
          user: 3682,
        },
        {
          word: "麦乐鸡",
          count: 3383,
          user: 3048,
        },
        {
          word: "炭烤",
          count: 8818,
          user: 26,
        },
        {
          word: "麻辣",
          count: 1297,
          user: 905,
        },
        {
          word: "冒菜",
          count: 3015,
          user: 2362,
        },
      ],

      saleRank: {
        online: {
          name: [
            "家用电器",
            "食用酒水",
            "个护健康",
            "服饰箱包",
            "母婴产品",
            "其他",
          ],
          value: [244, 321, 301, 41, 111, 69],
        },
        shop: {
          name: [
            "家用电器",
            "食用酒水",
            "个护健康",
            "服饰箱包",
            "母婴产品",
            "其他",
          ],
          value: [68, 15, 41, 56, 70, 25, 31],
        },
      },
    },
  });
});

//启动服务器
const port = 8080;
app.listen(port, () => {
  console.log(`本地服务器地址: http://localhost:${port}`);
});

// 运行命令：node app.js
// 浏览器访问 http://localhost:3000/api/user

// 运行结果：
// Server is running on port 3000
// 访问 http://localhost:3000/api/user 后返回
// {
//   "code": 200,
//   "message": "获取用户信息成功",
//   "data": {
//     "name": "时宜",
//     "age": 25,
//     "hobby": "coding"
//   }
// }

// 1.npm init -y
// 2.npm install express cors,npm install express-json
// const express = require('express');
// const cors = require('cors');
// const app = express();
// app.use(cors());
// app.use(express.json());

// 3.创建app.js文件
// 4.配置中间件
// 5.创建测试接口

// npm i nodemon -g
// 运行命令：nodemon app.js(cmd中运行)
// 本地浏览器只访问get请求,post、put、delete请求需要用Apifox插件

// //测试接口
// app.get('/api/user', (req, res) => {
//   res.send({
//     code: 200,
//     message: '获取用户信息成功',
//     data: {
//       name: '时宜',
//       age: 25,
//       hobby: 'coding'
//     }
//   });
// });

// // 创建用户
// app.post('/api/user/create', (req, res) => {
// //   const { name, age, hobby } = req.body;
//   // 假设创建成功
//   res.send({
//     code: 200,
//     message: '创建用户成功',
//     data: {
//       name: 'vvvv',
//       age: 24,
//       hobby: 'xxxx'
//     }
//   });
// });
// // 更新用户
// app.put('/api/user/update', (req, res) => {
//   // 假设更新成功
//   res.send({
//     code: 200,
//     message: '更新用户成功',
//     data: {
//       name: 'xxxxxx',
//       age: 26,
//       hobby: 'xxxxxx'
//     }
//   })
// });

// // 删除用户
// app.delete('/api/user/delete', (req, res) => {
//     // 假设删除成功
//     res.send({
//       code: 200,
//       message: '删除成功'
//     });
// });
